<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
>
<head th:include="includes/head :: htmlhead(~{::title}, ~{})">
    <meta charset="utf-8">
    <title>操作记录</title>
</head>
<body>
<div id="mainLayout" class="easyui-layout" data-options="fit: true">
    <div style="padding:0px;height:calc(100% - 30px)">
        <table id='dg' style="width:100%;height:100%"></table>
    </div>
    <div id="pg" style="height:30px" class="easyui-pagination">
    </div>
</div>

<script type="text/javascript">
    let ctxPath = '[[${#servletContext.contextPath}]]';
    $(function () {
        $(window).resize(function () {
            alert(2)
        });

        let toolbar = [{
            text: '刷新',
            iconCls: 'icon-diy-refresh1',
            handler: function () {
                pagingList(1, COMMONPARAM_DEFAULTPAGESIZE);
            }
        }];
        $('#dg').datagrid({
            data: []
            , columns: [
                [
                    {field: 'gmtCreate', title: '时间', resizable: true}
                    , {field: 'applyUserName', title: '申请用户名', resizable: true}
                    , {field: 'databaseName', title: '数据库名称', resizable: true}
                    , {field: 'affectLineNum', title: '操作的记录数', resizable: true}
                    , {field: 'runSql', title: '执行的sql', resizable: true}
                ]
            ]
            , autoRowHeight: true
            , rownumbers: true
            , singleSelect: true
            , toolbar: toolbar
        });

        $('#pg').pagination({
            pageList: COMMONPARAM_PAGELIST,
            pageSize: COMMONPARAM_DEFAULTPAGESIZE,
            total: 0,
            pageNumber: 1,
            beforePageText: '第',
            afterPageText: '页    共 {pages} 页',
            displayMsg: '当前显示 {from} - {to}条记录,共{total}条记录'
        });

        pagingList(1, COMMONPARAM_DEFAULTPAGESIZE);
    });

    function pagingList(pageNumber, pageSize) {
        let submitData = {};
        submitData['page'] = pageNumber;
        submitData['limit'] = pageSize;
        postJSON(ctxPath + '/mdmsUserLog/pagingList', submitData,
            function (data) {
                $('#dg').datagrid({
                    data: data['list']
                })
                $('#pg').pagination({
                    pageList: COMMONPARAM_PAGELIST,
                    pageSize: data['limit'],
                    total: data['total'],
                    pageNumber: data['page'],
                    beforePageText: '第',
                    afterPageText: '页    共 {pages} 页',
                    displayMsg: '当前显示 {from} - {to}条记录,共{total}条记录',
                    onSelectPage: function (pageNumber, pageSize) {
                        pagingList(pageNumber, pageSize);//选择第几页的时候，就刷新
                    },
                });
            }, function (result, resultdesc) {
                $.messager.show({
                    title: '异常',
                    msg: result + '-' + resultdesc,
                    showType: 'show'
                });
            }, function () {
                alert(3)
            }, function () {
                $.messager.progress(COMMONPARAM_PROCESS);
            }, function () {
                $.messager.progress('close');
            });
    }

</script>
</body>